<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
 <div id="dialog-message">
 <form id="register_from_class">
	<input type="hidden" id="table_id" value="${param.table_id}">
	 <table>
		 <tr id="cpid_1">
	 		<td width="50%">
	 		<fieldset>
				<label>上级ID：</label>
				<input type="text" id="cpid" value="" name="cpid"  maxlength="30"  />				
			</fieldset>
			<span class="help-block">上级ID</span> 
	 		</td> 
	 	</tr> 
	 	<tr>
	 		<td width="50%" id="pName_1">
	 		<fieldset>
				<label>上级：</label>
				<input type="text" id="pName" value=""  name="pName" meth="notNull" maxlength="30"  title="上级名称不能为空," />				
			</fieldset>
			<span class="help-block">增加为第一级集团，则不需要选择类型</span> 
	 		</td> 
	 	</tr> 
	 	
	 	<tr>
	 		<td width="50%">
	 		<fieldset>
			 
				 类型：&nbsp;&nbsp;
				   <div style="float:right;width:155px;">
 						<select class="width-155 form-control" id="type">
					<option value="1">集团</option>
					<option value="2">学校</option>  
					<option value="3">年级</option>  
					<option value="4">班</option>
				</select>
				</div> 
				
			</fieldset>
			<span class="help-block"></span> 
	 		</td> 
	 	</tr> 
	 	<tr>
	 		<td width="50%" id="lv_1">
	 		<fieldset>
			 
				 类型：&nbsp;&nbsp;
				   <div style="float:right;width:155px;">
 						<select class="width-155 form-control" id="lv">
				 		 <c:forEach items="${applicationScope.allLv}" var="ctemp">
						 	<option value="${ctemp.value1}">${ctemp.dictName}</option> 
						 </c:forEach>
				</select>
				</div>	
				<span class="help-block"></span> 
			</fieldset>
	 		</td> 
	 	</tr> 
	 	<tr>
	 		<td width="50%">
	 		<fieldset>
				<label>名称：</label>
				<input type="text" id="cname" value="${param.cname}"  require='true' name="cname" meth="notNull,isLength-2,notsm" maxlength="30"  title="名称不能为空,则名称不能小于三位,不能输入-特殊字符" />
				<span class="help-block">不为能空，不大于20个字符！</span> 
			</fieldset>
	 		</td> 
	 	</tr> 
	 	<tr id="addresss_1">
	 		<td width="50%">
	 		<fieldset>
				<label>地址：</label>
				<input type="text" id="addresss" value="${param.addresss}"  name="addresss" meth="" maxlength="30"  title="用户名称不能少于4位，由英文和数字组成" />
				<span class="help-block"></span> 
			</fieldset>
	 		</td> 
	 	</tr> 
	 	<tr>
	 		<td width="50%" id="cpassword_1">
	 		<fieldset>
				<label>班级默认密码：</label>
				<input type="text" id="cpassword" value="${param.cpassword}"   require='true' meth="notNull" name="cpassword"  maxlength="30"  title="班级密码不为空" />
				<span class="help-block">班级密码不为空</span> 
			</fieldset>
	 		</td> 
	 	</tr> 
	 </table>  
</form>	
</div>
<script type="text/javascript">
(function(){
	
	
	function addClass(contorl){
		var a =$("#register_from_class").hzValidate("init");  
		if(a==false){
			return;
		} 
		var object = OAajaxSubmit("register_from_class"); 
		 	//alert(obj2str(object));
			$.ajax({
			   type: "POST",
				url: "${pageContext.request.contextPath}/edu/sysClassAction.do?method=addClass&r="+Math.random(),
				data: object,
				dataType:'json',
			   success: function(msg){ 
			    	if(msg.code=="1"){
			    		alert(msg.message); 
			    		$(contorl).dialog("close"); 
			    		window.class1.loadTree();
			    	}else{
			    		alert(msg.message);
			    	}
			   }
			}); 
	} 
	//计算当前页面状态
	$(function(){ 
		var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
		var nodes = treeObj.getSelectedNodes();
		
		if(nodes.length==0){
			$("#lv_1").remove();
			$("#cpid_1").remove();
			$("#pName_1").remove();
			$("#cpassword_1").remove();
			for(var i=$("#type").find("option").length-1;i>=0;i--){ 
				if($($("#type").find("option")[i]).val()!=1){
					$($("#type").find("option")[i]).remove();
				}
			}
		}else{
			var temp = parseInt(nodes[0].type);
			//不是顶级，需要把班级别和密码去掉
			$("#cpid_1").hide();
			if(temp==1){
				$("#lv_1").remove(); 
				$("#cpassword_1").remove();
			}
			if(temp!=1){
				$("#addresss_1").remove();
			}
			 
			temp++;
			$("#cpid").val(nodes[0].cid);
			$("#pName").val(nodes[0].name);
			if(temp>3){
				temp=3;
				var pnode = nodes[0].getParentNode(); 
					$("#cpid").val(pnode.cid);
					$("#pName").val(pnode.name); 
			} 
			for(var i=$("#type").find("option").length-1;i>=0;i--){ 
				if($($("#type").find("option")[i]).val()!=temp){
					$($("#type").find("option")[i]).remove();
				}
			}
		}
	});
	window.classAdd={};
	window.classAdd.addClass = addClass;
})();
</script>
 